Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Mar 28, 2021

  • MVC.Cors
  • Mvc.DataAnnotations
  • Mvc.Localization
  • Mvc.Newtonsoft.Json
  • Mvc.ViewFeatures (partial)
  • Mvc.Razor

@pranavkm pranavkm requested a review from javiercn as a code owner March 28, 2021 19:06
@pranavkm pranavkm added this to the 6.0-preview4 milestone Mar 28, 2021
@pranavkm pranavkm added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 28, 2021
/// The delegate to invoke for creating <see cref="IStringLocalizer"/>.
/// </summary>
public Func<Type, IStringLocalizerFactory, IStringLocalizer> DataAnnotationLocalizerProvider;
public Func<Type, IStringLocalizerFactory, IStringLocalizer> DataAnnotationLocalizerProvider = null!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, weird that this is a field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, did not notice that. API-review fail :)

}

return _viewData;
return _viewData!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. Although the if block has a nice comment which says it's only ever run inside a unit test. I'd prefer to keep it that way.

@mkArtakMSFT mkArtakMSFT linked an issue Mar 29, 2021 that may be closed by this pull request
}

if (!(exception is JsonException || exception is OverflowException || exception is FormatException))
if (exception is not null && exception is not JsonException or OverflowException or FormatException)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy

}

public string Current => _attributes.Get(_index).Key;
public string? Current => _attributes.Get(_index).Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straight up bug. It's an enumerator for values (which can be null) but was returning the keys (which are non-nullable) instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing was affected by this though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not. You'd think we have a test for this. The usually pattern is to iterate over the dictionary itself which has the correct semantics.

* [x] MVC.Cors
* [x] Mvc.DataAnnotations
* [x] Mvc.Localization
* [x] Mvc.Newtonsoft.Json
* [ ] Mvc.ViewFeatures (partial)
@pranavkm pranavkm force-pushed the prkrishn/mvc-nullable branch from 20f1478 to b1ff989 Compare March 31, 2021 17:31
@pranavkm pranavkm force-pushed the prkrishn/mvc-nullable branch from b1ff989 to 76b7f9d Compare March 31, 2021 20:01
@pranavkm
Copy link
Contributor Author

This has been updated. I also covered nullability for Mvc.Razor while addressing some feedback

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

/// An <see cref="HttpContext"/> representing the current request execution.
/// </summary>
public HttpContext Context => ViewContext?.HttpContext;
public HttpContext Context => ViewContext?.HttpContext!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewContext can't be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice no. But in theory, if you're unit testing, you could have chosen to not initialize it. We want to avoid producing a null ref from the framework code in that case.

var page = new RazorPage();
page.HttpContext // fine if it's null here, but we want to avoid a NullReferenceException

}

public string Current => _attributes.Get(_index).Key;
public string? Current => _attributes.Get(_index).Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing was affected by this though?


[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MemberNotNull(nameof(_initialKeys), nameof(_retainedKeys), nameof(_data))]
private void AssertLoaded()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this method debug only?

public void Reset()
{
_enumerator.Reset();
((IEnumerator < KeyValuePair<string, object?>>)_enumerator).Reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, didn't get fixed

/// </exception>
/// <returns>This <see cref="ViewEngineResult"/> if <see cref="Success"/> is <c>true</c>.</returns>
public ViewEngineResult EnsureSuccessful(IEnumerable<string> originalLocations)
[MemberNotNull(nameof(View))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense

/// An <see cref="HttpContext"/> representing the current request execution.
/// </summary>
public HttpContext Context => ViewContext?.HttpContext;
public HttpContext Context => ViewContext?.HttpContext!;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice no. But in theory, if you're unit testing, you could have chosen to not initialize it. We want to avoid producing a null ref from the framework code in that case.

var page = new RazorPage();
page.HttpContext // fine if it's null here, but we want to avoid a NullReferenceException

/// Gets the dynamic view data dictionary.
/// </summary>
public dynamic ViewBag => ViewContext?.ViewBag;
public dynamic ViewBag => ViewContext?.ViewBag!;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same weird deal as RazorPageBase

{
string resolvedUrl;
if (TryResolveUrl(stringValue, resolvedUrl: out resolvedUrl))
if (TryResolveUrl(stringValue, resolvedUrl: out string? resolvedUrl))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an overloaded method and you have to specify the type for resolution

}

public string Current => _attributes.Get(_index).Key;
public string? Current => _attributes.Get(_index).Value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not. You'd think we have a test for this. The usually pattern is to iterate over the dictionary itself which has the correct semantics.

@ghost
Copy link

ghost commented Apr 1, 2021

Hello @pranavkm!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit b12b64e into main Apr 1, 2021
@ghost ghost deleted the prkrishn/mvc-nullable branch April 1, 2021 19:47
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update ASP.NET Core to use C# 8's nullable reference types

4 participants